Imports System.ComponentModel

Public Class Application
	Inherits ApplicationWrapperBase
	Implements IDisposable

	<Description("Konstruktor.")> _
	   Public Sub New(<Description("Nativni (COM+) objekt aplikace Outlook.")> ByVal nativeApplication As Object)
		MyBase.New(nativeApplication)
	End Sub

	<Description("Vytvori novou aplikaci Outlook.")> _
	Public Shared Function CreateApplication() As Application
		Dim mApp As Object = CreateObject("Outlook.Application")

		If mApp Is Nothing Then Throw New InvalidProgramException("Outlook.Application object was not created.")

		Return New Application(mApp)
	End Function

	'<Description("Ukonci aplikaci.")> _
	'   Public Sub Quit()
	'	Me.WrappedObject.Quit()
	'End Sub

	'<Description("Uvolni nativni (COM+) objekt aplikace.")> _
	'Friend Overridable Sub Dispose(ByVal flag As Boolean)
	'	If Not Me.WrappedObject Is Nothing And WrapperSettings.Default.CloseApplicationOnDispose Then
	'		Me.Quit()
	'	End If
	'End Sub

	'<Description("Uvolni nativni (COM+) objekt aplikace.")> _
	'Public Sub Dispose() Implements System.IDisposable.Dispose
	'	Me.Dispose(True)
	'	GC.SuppressFinalize(Me)
	'End Sub

	'<Description("Uvolni nativni (COM+) objekt aplikace.")> _
	'Protected Overrides Sub Finalize()
	'	'If Not Me.WrappedObject Is Nothing And WrapperSettings._Default.CloseApplicationOnDispose Then
	'	'    Me.Quit()
	'	'End If
	'	Me.Dispose(True)
	'End Sub

	Public Function CreateMailItem() As MailItem
		Dim result As MailItem

		Dim nativeItem = Me.GetWrappedObject().CreateItem(OlItemType.olMailItem)
		result = New MailItem(nativeItem, Me)

		Return result
	End Function
End Class
